home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Alles Voor Internet / Tout Pour Internet
/
alles voor internet.iso
/
MacInternet™
/
Telnet
/
NCSA
/
tn3270 2.3d26 source
/
tn3270
/
settings.c
< prev
next >
Wrap
Text File
|
1991-04-22
|
19KB
|
694 lines
/*
* tn3270 for the Macintosh Source Code
* Brown University Computing and Information Services
* Version 2.3d21, January 17, 1991
* Copyright (c) 1988, 1989, 1990, 1991 by Brown University and by
* Peter John DiCamillo.
*
* Permission is granted to any individual or institution to use, copy,
* or redistribute the binary version of this software and its
* documentation provided this notice and the copyright notices are
* retained. Permission is granted to any individual or non-profit
* institution to use, copy, modify, or redistribute the source files
* of this software provided this notice and the copyright notices are
* retained. This software may not be distributed for profit, either
* in original form or in derivative works, nor can the source be
* distributed to other than an individual or a non-profit institution.
* Any individual or group interested in seeing and/or using these
* source files but who are prevented from doing so by the above
* constraints should contact Don Wolfe, Assistant Vice-President for
* Computer Systems at Brown University, (401) 863-7250, for possible
* software licensing of the source developed at Brown.
*
* Brown University and Peter John DiCamillo make no representations
* about the suitability of this software for any purpose.
*
* BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
* EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
* INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#define __SEG__ 3270seg3
#include "maclib.h"
#include "termdef.h"
#include "globals.h"
#define eofErr -39
#include <ctype.h>
extern struct Point sfppoint, sfgpoint;
extern PaletteHandle myPalette;
OSErr fsrdopen();
init_settings()
{
short appmsg, appcount;
AppFile appinfo;
static char * ScrDmpEnb = (char *)0x2f8;
char changed;
OSErr read_settings();
/* adjust screen size default to match current display */
adjfmt(&changed, &(cs.windmax), &(cs.dfltptsize), &(cs.altptsize),
&(cs.altrows), &(cs.altcols));
/* initial file settings are defaults */
movmem(cshostname, fshostname, 128);
movmem(cskybdname, fskybdname, 256);
movmem(csnlname, fsnlname, 256);
strcpy(cssndname, dfltsoundname);
movmem(cssndname, fssndname, 256);
fs = cs;
/* define variable computed from settings */
serflg = (cs.setsflg == 1);
tcpflg = (cs.setsflg == 2);
if (tcpflg) strcpy(wtitle, "tn3270");
else strcpy(wtitle, "Mac3270");
if (cs.digitpfk) (*ScrDmpEnb) = 0;
else (*ScrDmpEnb) = ScrDmpSav;
fixbracket = cs.std_brack && (!aplmode) && (stdfont != ALAFONT);
/* attempt to get a file id for reading new settings */
/* first try file passed by the Finder (or whomever) */
CountAppFiles(&appmsg, &appcount);
if ((appmsg == appOpen) && (appcount > 0)) {
GetAppFiles(1, &appinfo);
ptoc(&appinfo.fName);
if (appinfo.fType == 'GFTS')
if (0 == get_settings(&appinfo.fName, appinfo.vRefNum, 1)) return(0);
}
/* Next, try a standard get file dialog */
if (0 == read_settings(1)) return(0);
return(1);
}
OSErr read_settings(initflg)
char initflg;
{
Point where;
ProcPtr fileFilter, dlgHook;
short numTypes;
SFTypeList typeList;
SFReply reply;
where = sfgpoint;
fileFilter = dlgHook = 0;
numTypes = 1;
typeList[0] = 'GFTS';
dlgHook = 0;
arrowcursor();
SFGetFile(&where, "Obtain settings from:", fileFilter,
numTypes, typeList, dlgHook, &reply);
if (reply.good == 0) return(8);
ptoc(&reply.fName);
return(get_settings(&reply.fName, reply.vRefNum, initflg));
}
get_settings(fname, vnum, initflg)
char * fname;
short vnum;
char initflg;
{
short fnum;
OSErr rc;
long count;
int t[67];
short colors[27];
char buffer[768];
char tstring[256];
char tstring2[256];
char tstring3[256];
char tstring4[256];
short tlen, tnum;
char scan_ok;
short i, j, len;
short tcount;
char tsave, changed;
char * tptr, * tend;
static char * ScrDmpEnb = (char *)0x2f8;
unsigned char **temph, **temph2;
Handle getsndresource();
short rid;
ResType rtype;
/* set default volume to initial settings location */
if (initflg) SetVol(0L, vnum);
rc = fsrdopen(fname, vnum, &fnum);
if (rc != 0) {
stoperr(rsetalrt);
return(rc);
}
count = 766;
rc = FSRead(fnum, &count, buffer);
FSClose(fnum);
if ((rc != 0) && (rc != eofErr)) {
stoperr(rsetalrt);
return(rc);
}
buffer[count] = 0; /* terminate C string */
tptr = buffer; /* initialize token pointer */
tcount = 0; /* initialize token count */
while (1) {
while (isspace(*tptr)) tptr++;
if ((*tptr) == 0) break;
tend = tptr;
while ((!isspace(*tend)) && ((*tend) != 0)) tend++;
tsave = (*tend);
(*tend) = 0;
if (tcount < 7) rc = sscanf(tptr, "%x", t+tcount);
else if (tcount == 7) rc = sscanf(tptr, "%d", t+tcount);
else if (tcount == 8) rc = sscanf(tptr, "%s", tstring);
else if (tcount < 18) rc = sscanf(tptr, "%d", t+tcount-1);
else if (tcount < 45) rc = sscanf(tptr, "%x", t+tcount-1);
else if (tcount < 47) rc = sscanf(tptr, "%d", t+tcount-1);
else if (tcount < 57) rc = sscanf(tptr, "%x", t+tcount-1);
else if (tcount == 57) rc = sscanf(tptr, "%s", tstring2);
else if (tcount < 59) rc = sscanf(tptr, "%x", t+tcount-2);
else if (tcount == 59) rc = sscanf(tptr, "%s", tstring3);
else if (tcount < 64) rc = sscanf(tptr, "%d", t+tcount-3);
else if (tcount == 64) rc = sscanf(tptr, "%s", tstring4);
else if (tcount < 71) rc = sscanf(tptr, "%x", t+tcount-4);
if (rc != 1) break;
tcount++;
if (tcount == 71) break;
(*tend) = tsave;
tptr = tend;
}
/* check validity of data */
scan_ok = 0;
if ((tcount == 16) || (tcount >= 45)) {
scan_ok = 1;
/* host name */
tlen = strlen(tstring);
if ((tlen > 127) || (tlen == 0)) scan_ok = 0;
if (strcmp(tstring, "''") == 0) tstring[0] = '\0';
/* t array */
/* tnum = number of array elements used */
tnum = tcount;
/* adjust for string settings */
if (tcount > 8) tnum--;
if (tcount > 57) tnum--;
if (tcount > 59) tnum--;
if (tcount > 64) tnum--;
for (i = 7; i < tnum; i++) {
if ((i >= 17) && (i <= 43)) continue; /* skip colors */
if ((i >= 50) && (i <= 52)) continue; /* status line color */
switch(i) {
case 8: /* connection type */
case 47: /* status line time */
if ((t[i] < 0) || (t[i] > 2)) scan_ok = 0;
break;
case 14: /* double-click */
if ((t[i] < 1) || (t[i] > 36)) scan_ok = 0;
break;
case 44: /* alternate rows */
case 59: /* custom rows */
if (t[i] < 24) scan_ok = 0;
break;
case 58: /* alternate columns */
case 60: /* custom columns */
if (t[i] < 80) scan_ok = 0;
break;
case 45: /* alternate font size*/
case 57: /* default font size */
if ((t[i] != 9) && (t[i] != 12)) scan_ok = 0;
break;
case 7: /* debug level */
case 9: /* timeout */
case 10: /* retries */
case 62: /* window h pos */
case 63: /* window v pos */
case 65: /* text creator */
break;
case 61: /* savewpos */
if ((t[i] < 0) || (t[i] > 2)) scan_ok = 0;
break;
default: /* boolean flags */
if ((t[i] != 0) && (t[i] != 1)) scan_ok = 0;
break;
}
}
if (tcount >= 58) {
tlen = strlen(tstring2); /* keymap name */
if ((tlen > 255) || (tlen == 0)) scan_ok = 0;
}
if (tcount >= 60) {
tlen = strlen(tstring3); /* national language */
if ((tlen > 255) || (tlen == 0)) scan_ok = 0;
}
if (tcount >= 65) {
tlen = strlen(tstring4); /* 'snd ' name */
if ((tlen > 255) || (tlen == 0)) scan_ok = 0;
}
/* check window position present if saved */
if (tcount >= 66) {
if ((t[61] == 2) && (tcount < 68)) scan_ok = 0;
}
}
if (scan_ok == 0) {
stoperr(ssetalrt);
return(12);
}
/* save name of good file */
movmem(fname, s_fName, 64);
for (i=0; i < 7; i++) fs.attrmap[i] = cs.attrmap[i] = t[i];
fs.dblevel = cs.dblevel = t[7];
if (initflg) {
fs.setsflg = cs.setsflg = t[8]; /* ignored if not initialization */
serflg = (cs.setsflg == 1); /* connection type can only be */
tcpflg = (cs.setsflg == 2); /* changed using the dialog */
}
if (!tcpflg) for (i=0; i < tlen; i++) tstring[i] = toupper(tstring[i]);
strcpy(fshostname, tstring);
strcpy(cshostname, tstring);
fs.timeout = cs.timeout = t[9];
fs.retries = cs.retries = t[10];
fs.insreset = cs.insreset = t[11];
fs.impnull = cs.impnull = t[12];
fs.digitpfk = cs.digitpfk = t[13];
if (cs.digitpfk) (*ScrDmpEnb) = 0;
else (*ScrDmpEnb) = ScrDmpSav;
fs.mousepf = cs.mousepf = t[14];
if (tcount >= 45) {
fs.basecolor = cs.basecolor = t[15];
fs.exactcolor = cs.exactcolor = t[16];
for (i=0; i < 27; i++) colors[i] = t[i+17];
movmem(colors, &fs.usrwhite, 54);
cs.usrwhite = fs.usrwhite;
cs.usryellow = fs.usryellow;
cs.usrpink = fs.usrpink;
cs.usrturquoise = fs.usrturquoise;
cs.usrgreen = fs.usrgreen;
cs.usrred = fs.usrred;
cs.usrblue = fs.usrblue;
cs.usrblack = fs.usrblack;
cs.usrback = fs.usrback;
if (tcount >= 54) {
cs.usrstat.red = fs.usrstat.red = t[50];
cs.usrstat.green = fs.usrstat.green = t[51];
cs.usrstat.blue = fs.usrstat.blue = t[52];
}
if (colormac && (myWindow != 0)) {
fixcolors(myPalette);
ActivatePalette(myWindow);
updCTab();
newbackcolor();
}
}
/* handle window position settings */
if (tcount >= 66) {
cs.savewpos = fs.savewpos = (t[61] > 0);
if (t[61] == 2) {
cs.windpth = fs.windpth = t[62];
cs.windptv = fs.windptv = t[63];
wposok = 1;
}
}
/* handle auto-connect setting */
if (tcount >= 69) {
cs.autoconn = fs.autoconn = t[64];
}
/* handle text creator setting */
if (tcount >= 70) {
cs.text_creator = fs.text_creator = t[65];
}
/* handle PS simulation setting */
if (tcount >= 71) {
cs.simps = fs.simps = t[66];
}
/* handle screen format settings */
if (tcount >= 61) { /* new format */
fs.altrows = cs.altrows = t[44];
fs.altptsize = cs.altptsize = t[45];
fs.windmax = cs.windmax = t[55];
fs.dfltptsize = cs.dfltptsize = t[57];
if (tcount >= 62) fs.altcols = cs.altcols = t[58];
if (tcount >= 63) fs.custrows = cs.custrows = t[59];
if (tcount >= 64) fs.custcols = cs.custcols = t[60];
}
else { /* old format */
if (tcount >= 46) fs.altrows = cs.altrows = t[44];
if (tcount >= 47)
fs.altptsize = cs.altptsize = fs.dfltptsize = cs.dfltptsize = t[45];
if (tcount >= 57) fs.windmax = cs.windmax = t[55];
fs.altcols = cs.altcols = 80;
}
adjfmt(&changed, &cs.windmax, &cs.dfltptsize, &cs.altptsize,
&cs.altrows, &cs.altcols);
if (changed) {
note_err(fmtalrt);
}
newwindfmt(); /* make changes now if possible */
if (tcount >= 58) copyrdstr(fskybdname, tstring2);
if (tcount >= 60) copyrdstr(fsnlname, tstring3);
if (tcount >= 65) copyrdstr(fssndname, tstring4);
if (tcount >= 48) fs.invertbw = cs.invertbw = t[46];
if (tcount >= 49) fs.stat_time = cs.stat_time = t[47];
if (tcount >= 50) fs.curpos = cs.curpos = t[48];
if (tcount >= 51) {
fs.blockcurs = cs.blockcurs = t[49];
if (myWindow != 0) newcur();
}
if (tcount >= 55) fs.ext3270 = cs.ext3270 = t[53];
if (tcount >= 56) {
fs.std_brack = cs.std_brack = t[54];
fixbracket = cs.std_brack && (!aplmode) && (stdfont != ALAFONT);
}
if (tcount >= 58) {
temph = GetNamedResource('GFKB', fskybdname);
if (temph == 0L) {
stoperr(kbsetalrt);
}
else {
kb_handle = temph;
GetResInfo(kb_handle, &rid, &rtype, tstring2);
strcpy(fskybdname, tstring2);
strcpy(cskybdname, tstring2);
}
}
if (tcount >= 59) fs.repnull = cs.repnull = t[56];
if (tcount >= 60) {
/* check for default */
GetItem(nlMenu, 1, tstring3);
if (strcmp(tstring3, fsnlname) == 0) {
strcpy(csnlname, tstring3);
nl_handle = 0;
newstdfont(NORMALFONT);
plainala = 0;
}
/* check resource */
else {
temph = GetNamedResource('GFNL', fsnlname);
if (temph == 0L) {
stoperr(nlsetalrt);
}
else {
GetResInfo(temph, &rid, &rtype, tstring3);
strcpy(fsnlname, tstring3);
strcpy(csnlname, tstring3);
if (GetHandleSize(temph) == 1) {
nl_handle = 0;
newstdfont(**temph);
plainala = 0;
}
else if (GetHandleSize(temph) == 3) {
nl_handle = 0;
newstdfont(**temph);
plainala = ((*temph)[1] & 0x80) == 0x80;
}
else {
nl_handle = temph;
defxtab(nl_handle, nltab);
newstdfont(NORMALFONT);
plainala = 0;
}
}
}
}
/* get non-purgeable copy of our sound resource */
if ((tcount >= 65) && newroms) {
if (strcmp(fssndname, dfltsoundname) == 0) {
if (sndactive) {
SndDisposeChannel(scp, true);
sndactive = 0;
}
if (sndhandle != 0) DisposHandle(sndhandle);
sndhandle = 0;
strcpy(cssndname, fssndname);
}
else {
temph = temph2 = getsndresource(fssndname);
if (temph == 0L) {
stoperr(sdsetalrt);
}
else {
rc = HandToHand(&temph2);
if (rc != noErr) {
ReleaseResource(temph);
stoperr(sdmemalrt);
}
else {
getsndinfo(temph, &rid, &rtype, tstring4);
ReleaseResource(temph);
if (sndactive) {
SndDisposeChannel(scp, true);
sndactive = 0;
}
if (sndhandle != 0) DisposHandle(sndhandle);
sndhandle = temph2;
strcpy(fssndname, tstring4);
strcpy(cssndname, tstring4);
}
}
}
}
strcpy(wtitle, fname);
if (myWindow == 0) return(0);
justGrowIcon(0);
invldscr();
cs.stat_time += 8; /* force time to be re-drawn */
newstat();
newinvbw();
SetWTitle(myWindow, wtitle);
return(0);
}
copyrdstr(dest, source)
unsigned char *dest, *source;
{
/* copy string, converting underscores to blanks */
register short i, j, len;
register char usflag;
len = strlen(source);
j = 0;
usflag = 0;
for (i=0; i < len; i++) {
if (source[i] == '_') {
if (usflag) {
dest[j++] = '_';
usflag = 0;
}
else {
usflag = 1;
}
}
else {
if (usflag) {
dest[j++] = ' ';
usflag = 0;
if (j == 255) break;
dest[j++] = source[i];
}
else {
dest[j++] = source[i];
}
}
if (j == 255) break;
}
if (usflag && (j < 255)) {
dest[j++] = ' ';
}
dest[j] = 0;
}
write_settings()
{
Point where;
ProcPtr dlgHook;
SFReply reply;
OSErr rc;
short fnum, i;
char s[640];
char tstring[128];
char tstring2[256];
char tstring3[256];
char tstring4[256];
long count;
char nullstr;
short savewpos;
where = sfppoint;
dlgHook = 0;
/* ctop(s_fName); */
arrowcursor();
SFPutFile(&where, "Save settings as:",
s_fName, dlgHook, &reply);
/* ptoc(s_fName); */
if (reply.good == 0) return;
ptoc(&reply.fName);
movmem(&reply.fName, s_fName, 64); /* save filename */
rc = FSDelete(&reply.fName, reply.vRefNum); /* delete existing file */
if ((rc != 0) && (rc != -43)) { /* file not found is ok */
stoperr(wsetalrt);
return;
}
rc = Create(&reply.fName, reply.vRefNum, 'GFTM', 'GFTS');
if (rc != 0) {
stoperr(wsetalrt);
return;
}
rc = FSOpen(&reply.fName, reply.vRefNum, &fnum);
if (rc != 0) {
stoperr(wsetalrt);
return;
}
/* update window position settings */
updwindpos();
savewpos = cs.savewpos;
if (savewpos && wposok) savewpos = 2;
/* save current values as file values */
movmem(cshostname, fshostname, 128);
movmem(cskybdname, fskybdname, 256);
movmem(csnlname, fsnlname, 256);
movmem(cssndname, fssndname, 256);
fs = cs;
movmem(cshostname, tstring, 128);
nullstr = 1;
for (i=0; i < 128; i++) {
if (tstring[i] == '\0') break;
if (tstring[i] == ' ') continue;
nullstr = 0;
break;
}
if (nullstr) strcpy(tstring, "''");
copywrstr(tstring2, cskybdname);
copywrstr(tstring3, csnlname);
copywrstr(tstring4, cssndname);
sprintf(s, "%x %x %x %x %x %x %x %d %s %d %d %d %d %d %d %d %d %d %x %x %x %x %x %x %x %x",
cs.attrmap[0], cs.attrmap[1], cs.attrmap[2], cs.attrmap[3],
cs.attrmap[4], cs.attrmap[5], cs.attrmap[6], cs.dblevel, tstring,
cs.setsflg, cs.timeout, cs.retries, cs.insreset, cs.impnull, cs.digitpfk,
cs.mousepf, cs.basecolor, cs.exactcolor, cs.usrwhite.red, cs.usrwhite.green,
cs.usrwhite.blue, cs.usryellow.red, cs.usryellow.green, cs.usryellow.blue,
cs.usrpink.red, cs.usrpink.green);
count = strlen(s);
rc = FSWrite(fnum, &count, s);
if (rc != 0) {
stoperr(wsetalrt);
return;
}
sprintf(s, " %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %d %d %x %x %x %x",
cs.usrpink.blue, cs.usrturquoise.red,
cs.usrturquoise.green, cs.usrturquoise.blue, cs.usrgreen.red, cs.usrgreen.green,
cs.usrgreen.blue, cs.usrred.red, cs.usrred.green, cs.usrred.blue, cs.usrblue.red,
cs.usrblue.green, cs.usrblue.blue, cs.usrblack.red, cs.usrblack.green,
cs.usrblack.blue, cs.usrback.red, cs.usrback.green, cs.usrback.blue,
cs.altrows, cs.altptsize, cs.invertbw, cs.stat_time, cs.curpos, cs.blockcurs);
count = strlen(s);
rc = FSWrite(fnum, &count, s);
if (rc != 0) {
stoperr(wsetalrt);
return;
}
sprintf(s, " %x %x %x %x %x %x %s %x %s %d %d %d %d %s %x %x %x %x %x %x",
cs.usrstat.red, cs.usrstat.green, cs.usrstat.blue, cs.ext3270,
cs.std_brack, cs.windmax, tstring2, cs.repnull, tstring3,
cs.dfltptsize, cs.altcols, cs.custrows, cs.custcols, tstring4,
savewpos, cs.windpth, cs.windptv, cs.autoconn, cs.text_creator,
cs.simps);
count = strlen(s);
rc = FSWrite(fnum, &count, s);
if (rc != 0) {
stoperr(wsetalrt);
return;
}
rc = FSClose(fnum);
if (rc != 0) stoperr(wsetalrt);
}
copywrstr(dest, source)
char *dest, *source;
{
register short i, j, len;
register unsigned char c;
len = strlen(source); /* copy name, converting blanks and underscores */
j = 0;
for (i=0; i < len; i++) {
c = source[i];
if (c == '_') {
dest[j++] = '_';
if (j == 255) break;
dest[j++] = '_';
}
else if (c == ' ') {
dest[j++] = '_';
}
else {
dest[j++] = c;
}
if (j == 255) break;
}
dest[j] = 0;
}
short new_settings()
{
short savepth, saveptv, rc;
if (strcmp(cshostname, fshostname) != 0) return(1);
if (strcmp(cskybdname, fskybdname) != 0) return(1);
if (strcmp(csnlname, fsnlname) != 0) return(1);
if (strcmp(cssndname, fssndname) != 0) return(1);
/* compare all other settings, except window position */
savepth = fs.windpth;
saveptv = fs.windptv;
fs.windpth = cs.windpth;
fs.windptv = cs.windptv;
rc = (fs != cs);
fs.windpth = savepth;
fs.windptv = saveptv;
return(rc);
}
OSErr fsrdopen(fname, vref, fref) /* open file read-only */
char * fname;
short vref;
short * fref;
{
IOParam pbi;
OSErr rc;
/* initialize parameter block */
setmem(&pbi, sizeof(IOParam), 0);
pbi.ioNamePtr = (StringPtr)fname;
pbi.ioVRefNum = vref;
pbi.ioPermssn = fsRdPerm;
ctop(fname);
rc = PBOpen(&pbi, 0);
*fref = pbi.ioRefNum;
ptoc(fname);
return(rc);
}
newwindfmt() /* make new screen format changes if possible */
{
if (myWindow == 0) return;
if ((cs.altrows == ses_altrows) && (cs.altcols == ses_altcols)) {
ses_altptsize = cs.altptsize;
ses_dfltptsize = cs.dfltptsize;
ses_windmax = cs.windmax;
newmode(cur_mode, 0);
}
else {
note_err(windfmtalrt);
}
}